import requests
import unittest
from weidujiankang.Tools import My_db


class Wdjk(unittest.TestCase):

    def setUp(self) -> None:
        print('开始测试')
        self.db = My_db('10.59.9.19', 'yidongceshi', 'Yd123456!', 'health')

    def tearDown(self) -> None:
        print('测试结束')
        self.db.close()

    # 内网环境
    host = 'http://10.59.9.18'

    # 登录
    userId = None
    sessionId = None
    userName = None
    def test_wdjk_01(self):
        r1 = requests.post(url=str(Wdjk.host)+'/health/user/v1/login', data={'email': '3500186206@qq.com', 'pwd': 'lZjdXyj15cOhn1a0yJKsW7o+fw/ogBDzn6CcyPSJUVIMmCPtCs+zuPwh7IZkXZiRhJvvjdIz9D2z1jkMOtD/36ddaLFMtQd9xIk0jAaDP1TH/lEHvvUPwot6asMGMGkH9EgBPT+4eaYC77BGQBPOASweQZE5KDF8BeN/c0sLfSw='})
        print(r1.json())
        Wdjk.userId = r1.json()['result']['userId']
        print(f'userId:{Wdjk.userId}')
        Wdjk.sessionId = r1.json()['result']['sessionId']
        print(f'sessionId:{Wdjk.sessionId}')
        # 响应断言
        self.assertIn('登录成功', r1.json()['message'])
        # 数据库断言
        Wdjk.userName = r1.json()['result']['userName']
        email1 = self.db.seatch(f"select email from user where user_name = '{Wdjk.userName}'")
        print(email1)
        self.assertEqual('3500186206@qq.com', email1[0][0])


    # 查询科室列表
    # 科室Id
    departmentId = None
    def test_wdjk_02(self):
        r2 = requests.get(url=str(Wdjk.host)+'/health/share/knowledgeBase/v1/findDepartment')
        print(r2.json())
        Wdjk.departmentId = r2.json()['result'][0]['id']
        print(f'科室Id:{Wdjk.departmentId}')

    # 病友圈列表展示
    # 病友圈Id
    sickCircleId = None
    def test_wdjk_03(self):
        r3 = requests.get(url=str(Wdjk.host)+'/health/user/sickCircle/v1/findSickCircleList',
                          params={'departmentId': Wdjk.departmentId, 'page': 1, 'count': 5})
        print(r3.json())
        Wdjk.sickCircleId = r3.json()['result'][0]['sickCircleId']
        print(f'病友圈Id：{Wdjk.sickCircleId}')

    # 正向用例1：case_001：输入正确的参数发表评论，评论成功
    # 病友圈发表评论
    def test_wdjk_04(self):
        r4 = requests.post(url=str(Wdjk.host)+'/health/user/sickCircle/verify/v1/publishComment',
                           headers={'userId': str(Wdjk.userId), 'sessionId': str(Wdjk.sessionId)},
                           params={'sickCircleId': str(Wdjk.sickCircleId), 'content': '保持好心情！'})
        print(r4.json())

    # 正向用例2：case_002：建议内容参数输入内容为最大允许长度发表评论，评论成功
    # 病友圈发表评论
    def test_wdjk_05(self):
        r5 = requests.post(url=str(Wdjk.host)+'/health/user/sickCircle/verify/v1/publishComment',
                           headers={'userId': str(Wdjk.userId), 'sessionId': str(Wdjk.sessionId)},
                           params={'sickCircleId': str(Wdjk.sickCircleId), 'content': '保持好心情！保持好心情！保持好心情！'})
        print(r5.json())

    # 正向用例3：case_003：输入重复建议内容并发表评论，评论成功
    # 病友圈发表评论
    def test_wdjk_06(self):
        r6 = requests.post(url=str(Wdjk.host)+'/health/user/sickCircle/verify/v1/publishComment',
                           headers={'userId': str(Wdjk.userId), 'sessionId': str(Wdjk.sessionId)},
                           params={'sickCircleId': str(Wdjk.sickCircleId), 'content': '保持好心情！'})
        print(r6.json())







if __name__ == '__main__':
    unittest.main()



